import request from "@/utils/request";

/**
 * 库存列表
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getStockGoodsList(params = {}){
  return request({
    url: '/stock/getStockGoodsList',
    method: 'get',
    params,
    timeout: 60000 * 5, // 1分钟
  })
}

/**
 * 获取库存详情
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function getStockInfo(id){
  return request({
    url: `/stock/getStockInfo/${id}`,
    method: 'get',
  })
}

/**
 * 删除库存商品
 * @param id
 * @returns {Promise | Promise<unknown>}
 */
export function delStockGoods(id){
  return request({
    url: `/stock/delStockGoods/${id}`,
    method: 'delete',
  })
}

/**
 * 保存关联库存商品
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function saveStockGoods(data){
  return request({
    url: `/stock/saveStockGoods`,
    method: 'post',
    data,
  })
}

/**
 * 修改库存数量
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function editStockNum(data){
  return request({
    url: `/stock/editStockNum`,
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 库存商品关联适用
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function suitStockGoods(data){
  return request({
    url: '/stock/suitStockGoods',
    method: 'post',
    data
  })
}

/**
 * 提交入库单
 * @param data
 * @returns {Promise<unknown>}
 */
export function addStock(data){
  return request({
    url: '/stock/addStock',
    method: 'post',
    data,
    handleError: true,
  })
}

/**
 * 获取入库单列表
 * @param params
 * @returns {Promise<unknown>}
 */
export function getStockOrderList(params = {}){
  return request({
    url: '/stock/getStockOrderList',
    method: 'get',
    params
  })
}

/**
 * 获取入库单详情
 * @param stockOrderNo
 * @returns {Promise<unknown>}
 */
export function getStockOrder(stockOrderNo){
  return request({
    url: `/stock/getStockOrder/${stockOrderNo}`,
    method: 'get',
  })
}

/**
 * 获取库存的说明
 * @returns {Promise | Promise<unknown>}
 */
export function getStockHelp(){
  return request({
    url: '/stock/getStockHelp',
  })
}

/**
 * 删除库存
 * @param stockId
 * @returns {Promise<unknown>}
 */
export function deleteStock(stockId){
  return request({
    url: `/stock/${stockId}`,
    method: 'delete',
  })
}

/**
 * 修改库存快递单
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function saveStockOrderExpress(data){
  return request({
    url: `/stock/saveStockOrderExpress`,
    data,
    method: 'post',
    handleError: true,
  })
}

/**
 * 获取官方仓
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getFullGoodsList(params){
  return request({
    url: `/stock/getFullGoodsList`,
    params
  })
}

/**
 * 生成sku标签数据
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function createSkuInfoData(params){
  return request({
    url: `/stock/createSkuInfoData`,
    params,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}

/**
 * 下载sku标签
 * @param data
 * @returns {Promise<unknown>}
 */
export function downloadSkuInfoData(data){
  return request({
    url: `/stock/downloadSkuInfoData`,
    method: 'post',
    data,
    responseType: "blob", // 需要加上
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}

/**
 * 打印sku标签
 * @param data
 * @returns {Promise<unknown>}
 */
export function printSkuInfoData(data){
  return request({
    url: `/stock/downloadSkuInfoData`,
    method: 'post',
    data,
    responseType: "arraybuffer",
    isNotJson: true,
    timeout: 60000 * 5, // 1分钟
    handleError: true,
  })
}


/**
 * 修改组转费用
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function saveGoodsCombinationFee(data){
  return request({
    url: `/stock/saveGoodsCombinationFee`,
    method: 'put',
    data,
  })
}

/**
 * 获取库存日记
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getStockLog(params = {}){
  return request({
    url: '/stock/getStockLog',
    params,
  })
}

/**
 * 获取库存箱数据
 * @param params
 * @returns {Promise<unknown>}
 */
export function getBoxStockLog(params = {}){
  return request({
    url: '/stock/getBoxStockLog',
    params,
  })
}

/**
 * 获取小包商品的库存列表
 * @param params
 * @returns {Promise<unknown>}
 */
export function getPacketStockGoodsList(params = {}){
  return request({
    url: '/stock/getPacketStockGoodsList',
    method: 'get',
    params
  })
}

/**
 * 修改小包商品库存（系统标一件代发）
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function savePacketStockNum(data){
  return request({
    url: '/stock/savePacketStockNum',
    data,
    method: 'put',
  })
}


/**
 * 获取箱唛
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getBoxLabelGoods(params = {}){
  return request({
    url: '/stock/getBoxLabelGoods',
    params,
  })
}

/**
 * 修改箱唛库存
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function editBoxLabelGoodsNum(data){
  return request({
    url: '/stock/editBoxLabelGoodsNum',
    method: 'put',
    data,
    handleError: true,
  })
}


/**
 * 修改混装库存
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function editMixinStockNum(data){
  return request({
    url: '/stock/editMixinStockNum',
    method: 'put',
    data,
    handleError: true,
  })
}

/**
 * 获取箱的库存
 * @param params
 * @returns {Promise | Promise<unknown>}
 */
export function getBoxStock(params){
  return request({
    url: '/stock/getBoxStock',
    params,
  })
}

/**
 * 修改箱的库存
 * @param data
 * @returns {Promise | Promise<unknown>}
 */
export function editBoxStockNum(data){
  return request({
    url: '/stock/editBoxStockNum',
    method: 'put',
    data,
    handleError: true,
  })
}
